#include <iostream>
#include <cstring>
#include <utility>
#include <queue>

using namespace std;

int edges[1111][1111][4]; // up right down left
int dr[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};
bool seen[1111][1111];
int dfs(int r, int c) {
    if (seen[r][c]) return 0;
    queue<pair<int,int> > Q;
    Q.push(make_pair(r,c));
    while (Q.size()) {
      r = Q.front().first, c = Q.front().second; Q.pop();
      int res = 1;
      for (int k = 0 ; k < 4 ; k ++ ) {
         if (edges[r][c][k]) continue;
         int rr = r + dr[k], cc = c + dc[k];
         if (!seen[rr][cc]) {
           seen[rr][cc] = 1;
           Q.push(make_pair(rr,cc));
         }
      }
    }
    return 1;
}

int main() {
    int i,j , k;
    int N;
    while (cin >> N) {
        memset(edges, 0, sizeof(edges));
        memset(seen, false, sizeof(seen));
        for (int r = 0; r < 2 * N; ++r) edges[r][0][3] = edges[r][2*N][1] = 1;
        for (int c = 0; c < 2 * N + 1; ++c) edges[0][c][0] = edges[2*N-1][c][2] = 1;
        for (int r = 0; r < 2 * N - 1; ++r ) {
            string s; cin >> s;
            int offset = 0;
            if (r & 1) offset ++;
            for (int c = 0; c < N ; ++c) {
                if (s[c] == 'H') {
                    edges[r][2*c+offset][2] = 1;
                    edges[r+1][2*c+offset][0] = 1;
                    // segunda aleta...
                    edges[r][2*c+offset+1][2] = 1;
                    edges[r+1][2*c+offset+1][0] = 1;
                } else {
                    edges[r][2*c+offset][1] = 1;
                    edges[r][2*c+1+offset][3] = 1;
                    // segunda aleta
                    edges[r+1][2*c+offset][1] = 1;
                    edges[r+1][2*c+1+offset][3] = 1;
                }
            }
        }
        //return 0;
        int regiones = 0;
        for ( i = 0 ; i < 2 * N ; ++i) for ( j = 0 ;j  < 2*N + 1 ; ++j) if (dfs(i,j)) regiones++;
        cout << regiones-1 << endl;
    }
    return 0;
}
